# https://stackoverflow.com/questions/34255938/is-there-a-way-to-specify-the-width-of-a-rectangle-in-pil
# 给定一张武侠图片的地址 给该图片加边框
import sys
from PIL import Image, ImageDraw, ImageFont
# get an image
img = Image.new('RGB', (200,200), (255,255,255,0))

draw = ImageDraw.Draw(img)
draw.rectangle(((0, 0), (190, 190)), outline="#000000")

font = ImageFont.truetype('/Library/Fonts/Songti.ttc', 30);
draw.text((10,60), "玉女心经", font=font, fill=(0,0,0))
del draw

img.save("output.jpg");


if __name__ == "__main__":
    border_width = 5;
    color_list = ["#000000", "#25d1b3", "#fedc62", "#fc3c63"]
    for cardId in range(75):
        if cardId != 0:
            for index, color in enumerate(color_list):
                # img = Image.open("/Users/xppiao/Desktop/wuxia/wx%s.jpg" % sys.argv[1]).convert("RGB");
                img = Image.open("/Users/xppiao/Desktop/wuxia/wx%s.jpg" % cardId).convert("RGB");
                draw = ImageDraw.Draw(img);

                draw.rectangle(((0,0),(img.size[0], border_width)), fill=color, outline=color)
                draw.rectangle(((0,0),(border_width, img.size[1])), fill=color, outline=color)
                draw.rectangle(((img.size[0] - border_width,0),(img.size[0], img.size[1])), fill=color, outline=color)
                draw.rectangle(((0,img.size[1] - border_width),(img.size[0], img.size[1])), fill=color, outline=color)
                del draw
                img.save("/Users/xppiao/Desktop/wuxia/wx%s_%s.jpg" % (cardId, index));
            print("%s成功" % cardId);

